package weblab.tutor;

import utils.UserTasks;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class WebUserInterface {
	
    
    Context mContext;   

    /** Instantiate the interface and set the context */
    WebUserInterface(Context c) {
        mContext = c;
    }

    /** Show a toast from the web page */
  //@JavascriptInterface
    public void registerUser(String username, String password, String email) {
    	try{
    		new UserTasks(mContext).execute(username,password,email, "register");
//    		Toast.makeText(mContext, "User successfully registered!", Toast.LENGTH_SHORT).show();

    	}
    	catch(Exception e){
    		e.printStackTrace();
    	}
    }
    
    public void loginUser(String password, String email) {
    	try{
    		new UserTasks(mContext).execute(password,email,"login");
    	}
    	catch(Exception e) {
    		e.printStackTrace();
    	}
    }
    
    public void switchToRegister(){
    	Intent i=new Intent(mContext, RegisterActivity.class);
    	mContext.startActivity(i);
    }
    public void switchToDoItYourself(){
    	Intent i=new Intent(mContext, TryItYourself.class);
    	mContext.startActivity(i);
    }
    
    public void switchToLessons(){
    	Intent i=new Intent(mContext, LessonListActivity.class);
    	mContext.startActivity(i);
    }
    
    public void switchToTakeQuiz(){
    	Intent i=new Intent(mContext, QuizListActivity.class);
    	mContext.startActivity(i);
    }
    
    /** Show a toast from the web page */
    
    public void showToast(String toast, String type) {
        if(type.equals("register")) Toast.makeText(mContext, "Registration successful!", Toast.LENGTH_SHORT).show();
    }

}
